package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.dao.CategoryReportMapper;
import com.qingcheng.pojo.order.CategoryReport;
import com.qingcheng.service.order.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @Author:boy
 * @Date:2019/7/1
 * @description:
 * @ModifiedBy:
 */
@Service(interfaceClass = CategoryReportService.class)
public class CategoryReportServiceImpl implements CategoryReportService {
    @Autowired
    private CategoryReportMapper categoryReportMapper;

    public List<CategoryReport> categoryReport(LocalDate date) {
        return categoryReportMapper.categoryReport(date);
    }

    @Transactional
    public void createData() {
        LocalDate date = LocalDate.now().minusDays(1);
        List<CategoryReport> categoryReports = this.categoryReport(date);
        if (categoryReports != null && categoryReports.size() > 0) {
            for (CategoryReport categoryReport : categoryReports) {
                categoryReportMapper.insert(categoryReport);
            }
        }
    }

    public List<Map> category1Count(String date1, String date2) {
        return categoryReportMapper.category1Count(date1, date2);
    }
}
